<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <title>Document</title>
</head>
<body>
      
    <button  id="btn">开关灯</button>
 
             <script>
                 var b = document.getElementById("btn");
                    b.onclick=function()
                   {
                       var faly = 1;
                       if(faly==1)
                       {
                        document.body.style.backgroundColor="red";
                        faly=0;
                       }
                       if(faly==0)
                       {
                        document.body.style.backgroundColor="#fff";
                          faly=1;
                       }
                   }   

             </script>

</body>
</html>